import request from '../utils/request'

export default {
    // 开启命名空间
    namespace: 'home',
    state: {
        count: 10000,
        list: []
    },
    // 修改数据
    reducers: {
        ADD(state, action) {
            state.count += 1
            return {
                ...state
            }
        },
        INIT_LIST(state, { list }) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState.list = list
            return NewState
        }
    },
    effects: {
        *init({}, { put }) {  // eslint-disable-line
            const data = yield request("https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata")
            yield put({ type: 'INIT_LIST', list: data.data.message });
        },
    },
    subscriptions: {
        // init({ dispatch }) {
        //     dispatch({ type: "init" })
        // }

        // init({ history, dispatch }) {
        //     if (history.location.pathname === "/home") {
        //         // alert('准备拦截')
        //     }
        // }
    }
};
